package org.example.mpdemo1.mapper;

import org.example.mpdemo1.entity.Ams;
import org.example.mpdemo1.entity.Instrument;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;

@Repository
public interface InstrumentMapper extends Mapper<Instrument> {
//
//    @Select("select * from instrument where id=#{id}")
//    Instrument findById(int id);

    @Select("select * from instrument")
    List<Instrument> getAll();

    //ams中的属性是查询条件，包含name和state
    @Select("select * from instrument where name like concat('%',#{ams.name},'%') and state=#{ams.state}")
    List<Instrument> findBySearch(@Param("ams") Ams ams);

    //包含name的查询
    @Select("select * from instrument where name like concat('%',#{name},'%')")
    List<Instrument> findByName(String name);

    @Delete("delete from instrument where id=#{id}")
    void delete1(@Param("id")int id);

    @Select("select * from instrument where id=#{id}")
    Instrument selectById(Integer id);

    @Update("UPDATE instrument  SET name = #{ins.name},type = #{ins.type},ip = #{ins.ip},description=#{ins.description}, owner=#{ins.owner}, startTime=#{ins.startTime},endTime=#{ins.endTime},state=#{ins.state} where id=#{ins.id} ")
    void updateBySdKey(@Param("ins") Instrument instrument);

    @Insert("INSERT INTO instrument (name, type, ip, description, owner, startTime, endTime, state) VALUES (#{ins.name}, #{ins.type}, #{ins.ip}, #{ins.description}, #{ins.owner}, #{ins.startTime}, #{ins.endTime}, #{ins.state})")
    void insertIn(@Param("ins") Instrument instrument);

}
